package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.utils.MinioUtil;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.UUID;

@Slf4j
@RestController
@RequestMapping("/admin/common")
public class CommonController {
    @Resource
    private MinioUtil minioUtil;
    @PostMapping("/upload")
    @ApiOperation("文件上传")
    public Result<String> upload(@RequestParam("file") MultipartFile file){
        log.info("{}",file);
//        String name = file.getOriginalFilename();
        String newFileName = UUID.randomUUID().toString() ;//+ "." + name.substring(name.lastIndexOf(".")+1);
        String url = minioUtil.upload(file, newFileName);
        if(url!=null)
            return Result.success(url);
        return Result.error("上传失败");
    }

}
